package com.goods.controller.business;

import com.goods.business.service.ProductService;
import com.goods.common.model.business.Product;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductStockVO;
import com.goods.common.vo.business.ProductVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Title:
 * Author: fusu
 * DateTime:  2023/3/24
 * Description:
 **/
@Api(tags = "物资资料-物资资料接口")
@RestController
@RequestMapping("/business/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @ApiOperation(value = "物资资料分页列表")
    @GetMapping("/findProductList")
    public ResponseBean findProductList(@RequestParam("pageNum") Integer pageNum,
                                        @RequestParam("pageSize") Integer pageSize,
                                        @RequestParam(value = "name", required = false) String name,
                                        @RequestParam(value = "categorys", required = false) List<Long> categorys,
                                        @RequestParam(value = "status", required = false) Integer status) {
//        System.out.println(categorys);
        PageVO pagevo = productService.findProductList(pageNum, pageSize, name, categorys, status);
        return ResponseBean.success(pagevo);
    }

    @ApiOperation(value = "物资资料添加")
    @PostMapping("/add")
    public ResponseBean addProduct(@RequestBody ProductVO productVO) {
        productService.addProduct(productVO);
        return ResponseBean.success();
    }

    @ApiOperation(value = "物资资料根据id获取")
    @GetMapping("/edit/{productId}")
    public ResponseBean getByProductId(@PathVariable("productId") Long productId) {
        Product product = productService.getByProductId(productId);
        return ResponseBean.success(product);
    }

    @ApiOperation(value = "物资资料根据id修改")
    @PutMapping("/update/{productId}")
    public ResponseBean updateByProductId(@PathVariable("productId") Long productId,
                                          @RequestBody Product product) {
        product.setId(productId);
        productService.updateByProductId(product);
        return ResponseBean.success();
    }

    @ApiOperation(value = "物资资料根据id放入回收站")
    @PutMapping("/remove/{productId}")
    public ResponseBean removeByProductId(@PathVariable("productId") Long productId) {
        productService.removeByProductId(productId);
        return ResponseBean.success();
    }

    @ApiOperation(value = "物资资料根据id删除")
    @DeleteMapping("/delete/{productId}")
    public ResponseBean deleteByProductId(@PathVariable("productId") Long productId) {
        productService.deleteByProductId(productId);
        return ResponseBean.success();
    }

    @ApiOperation(value = "物资资料根据id恢复")
    @PutMapping("/back/{productId}")
    public ResponseBean bactProduct(@PathVariable("productId") Long productId) {
        productService.bactProduct(productId);
        return ResponseBean.success();
    }

    @ApiOperation(value = "物资资料根据id通过")
    @PutMapping("/publish/{productId}")
    public ResponseBean publishProduct(@PathVariable("productId") Long productId) {
        productService.publishProduct(productId);
        return ResponseBean.success();
    }

    @ApiOperation(value = "物资资料列表")
    @GetMapping("/findProducts")
    public ResponseBean findProducts(@RequestParam("pageNum") Integer pageNum,
                                     @RequestParam("pageSize") Integer pageSize,
                                     @RequestParam(value = "name", required = false) String name,
                                     @RequestParam(value = "categorys", required = false) List<Long> categorys,
                                     @RequestParam(value = "status", required = false) Integer status) {
//        System.out.println(categorys);
        PageVO pagevo = productService.findProductList(pageNum, pageSize, name, categorys, status);
        return ResponseBean.success(pagevo);
    }

    @ApiOperation(value = "获取物资库存信息")
    @GetMapping("/findAllStocks")
    public ResponseBean findAllStocks(@RequestParam("pageNum") Integer pageNum,
                                      @RequestParam("pageSize") Integer pageSize,
                                      @RequestParam(value = "name", required = false) String name,
                                      @RequestParam(value = "categorys", required = false) List<Long> categorys) {
        PageVO pageVO = productService.findAllStocks(pageNum, pageSize, name, categorys);
        return ResponseBean.success(pageVO.getRows());
    }

    @ApiOperation(value = "分页获取物资库存信息")
    @GetMapping("/findProductStocks")
    public ResponseBean  findProductStocks(@RequestParam("pageNum") Integer pageNum,
                                           @RequestParam("pageSize") Integer pageSize,
                                           @RequestParam(value = "name", required = false) String name,
                                           @RequestParam(value = "categorys", required = false) List<Long> categorys) {
        PageVO pageVO = productService.findAllStocks(pageNum, pageSize, name, categorys);
        return ResponseBean.success(pageVO);
    }

}
